﻿using Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
   public class UserinfoDAL
    {
        public static Model.Userinfo GetUserinfo(string name,string password)
        {
            //查询sql语句
            string sql = "select * from [User] where Account=@name and Password=@password";
            //参数对象
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@name",name),
                new SqlParameter("@password",password)
            };
            //执行查询语句
            SqlDataReader reader =DBHelper.ExecuteReader(sql, System.Data.CommandType.Text, paras);

            //集合
            List<Model.Userinfo> lst = new List<Userinfo>();
            //读取下一条
            if (reader.Read())
            {
                //实例化对象
                Userinfo user = new Userinfo
                {
                    Account = reader["Account"].ToString(),
                    Password = reader["Password"].ToString(),
                    UserID = Convert.ToInt32(reader["UserID"]),
                    UserName = reader["UserName"].ToString(),
                    Sex=Convert.ToInt32( reader["Sex"]),
                    Email=reader["Email"].ToString(),
                    Phone=reader["Phone"].ToString(),
                    
                    
                };

                lst.Add(user);
               
            }
            //判断
            if (lst.Count > 0)
            {
                return lst[0];
            }
            else
            {
                return null;
            }
        }
        
    }
}
